package com.itheima.controller;

import com.itheima.pojo.*;
import com.itheima.service.StudentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.security.DrbgParameters;
import java.util.List;

@RestController
@RequestMapping("/students")
@Slf4j
public class StudentController {
    @Autowired
    private StudentService studentService;
    @GetMapping
    public Result page(StudentQueryParam studentQueryParam) {
        PageResult pageResult = studentService.page(studentQueryParam);

    return Result.success(pageResult);
    }
    @DeleteMapping("/{ids}")
    public Result delete(@PathVariable List<Integer> ids){
      //  log.info("批量删除部门: ids={} ", ids);
        studentService.deleteByIds(ids);
        return Result.success();
    }
    @GetMapping("/{id}")
    public Result getInfo(@PathVariable Integer id){
        log.info("根据id查询员工的详细信息");
        Student student = studentService.getInfo(id);
        return Result.success(student);
    }
    /**
     * 更新员工信息
     */
    @PutMapping
    public Result update(@RequestBody Student student){
        log.info("修改员工信息, {}", student);
        studentService.update(student);
        return Result.success();
    }
    @PostMapping
    public Result add(@RequestBody Student student){
        studentService.save(student);
        return Result.success();
    }
    @PutMapping("/violation/{id}/{score}")
    public Result update(@PathVariable Integer id, @PathVariable Integer score){

        studentService.update(id,score);
        return Result.success();
    }
}
